using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Collections.ObjectModel;

namespace SharedContent
{
    public class InputManager
    {
        public Dictionary<Keys, string> keyboardHandlers;
        public Dictionary<Buttons, string> gamePadHandlers;
        private Dictionary<Keys, string> keyboardHandlersbackup;
        private Dictionary<Buttons, string> gamePadHandlersbackup; 

        public List<Keys> getKeysFor(string value)
        {
            List<Keys> keys = new List<Keys>();
            foreach (KeyValuePair<Keys, string> pair in keyboardHandlers)
            {
                if (pair.Value == value)
                    keys.Add(pair.Key);
            }
            return (keys);
        }
        public List<Buttons> getButtonsFor(string value)
        {
            List<Buttons> keys = new List<Buttons>();
            foreach (KeyValuePair<Buttons, string> pair in gamePadHandlers)
            {
                if (pair.Value == value)
                    keys.Add(pair.Key);
            }
            return (keys);
        }
        public void shuffle()
        {
            Random r = new Random();
            keyboardHandlersbackup = keyboardHandlers;
            gamePadHandlersbackup = gamePadHandlers;
            List<Keys> keys = new List<Keys>(keyboardHandlers.Keys.ToArray());
            List<string> methods = new List<string>(keyboardHandlers.Values.ToList());
            int i = 0;
            int j = 0;
            if (methods.Count == 0)
                return;
            keyboardHandlers = new Dictionary<Keys, string>();
            foreach (Keys k in keys)
            {
                i += r.Next();
                i %= methods.Count;
                keyboardHandlers.Add(k, methods[i]);
                methods.Remove(methods[i]);

            }
        }
        public void reset()
        {
            keyboardHandlers = keyboardHandlersbackup;
            gamePadHandlers = gamePadHandlersbackup;
        }
    }
    public class Level
    {
        InputManager inputManager;

    }
}
